/*
 * 创建日期 2011-3-3
 *
 * 成都天和软件公司
 * 电话：028-85425861 
 * 传真：028-85425861-8008 
 * 邮编：610041 
 * 地址：成都市武侯区航空路6号丰德万瑞中心B座1001 
 * 版权所有
 */
package  org.fantasy.common.db.pool;

/**
 * 数据库配置
 * 
 * @author 王文成
 * @version 1.0
 * @since 2011-3-24
 */
public class DBOptions {

	/**
	 * 驱动
	 */
	private String driverClassName = "org.olap4j.driver.xmla.XmlaOlap4jDriver";

	/**
	 * 数据库访问链接
	 */
	private String databaseURL;

	/**
	 * 用户名
	 */
	private String user;

	/**
	 * 密码
	 */
	private String password;

	/**
	 * 最小连接数
	 */
	private int minConnection = 5;

	/**
	 * 最大连接数
	 */
	private int maxConnection = 100;

	/**
	 * 连接超时
	 */
	private int timeout = 500;

	public DBOptions(String ip, String db) {
		this.databaseURL = "jdbc:xmla:Server=http://" + ip + "/OLAP/msmdpump.dll;Catalog=" + db;
	}

	public DBOptions() {

	}

	public String getDatabaseURL() {
		return databaseURL;
	}

	public void setDatabaseURL(String databaseURL) {
		this.databaseURL = databaseURL;
	}

	public String getDriverClassName() {
		return driverClassName;
	}

	public void setDriverClassName(String driverClassName) {
		this.driverClassName = driverClassName;
	}

	public int getMaxConnection() {
		return maxConnection;
	}

	public void setMaxConnection(int maxConnection) {
		this.maxConnection = maxConnection;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public int getMinConnection() {
		return minConnection;
	}

	public void setMinConnection(int minConnection) {
		this.minConnection = minConnection;
	}

	public int getTimeout() {
		return timeout;
	}

	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}

	public boolean isJdbc() {
		return !isOlap();
	}

	public boolean isOlap() {
		boolean isOlap = "org.olap4j.driver.xmla.XmlaOlap4jDriver".equals(driverClassName);
		return isOlap;
	}

	@Override
	public String toString() {
		StringBuilder s = new StringBuilder();
		s.append("[");
		s.append(databaseURL);
		s.append(";");
		s.append(driverClassName);
		s.append("]");
		return s.toString();
	}

	@Override
	public int hashCode() {
		return toString().hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj instanceof DBOptions) {
			DBOptions another = (DBOptions) obj;
			boolean b1 = driverClassName.equals(another.getDriverClassName());
			boolean b2 = databaseURL.equals(another.getDatabaseURL());
			return b1 && b2;
		}
		return false;
	}
}
